package CustomUI;

import com.example.dworld3.Draw;
import com.example.dworld3.Drawings;
import com.ydev.dworld3.R;

import android.app.Activity;
import android.app.Dialog;
import android.content.Context;
import android.graphics.drawable.ColorDrawable;
import android.view.View;
import android.view.Window;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.EditText;
import android.widget.LinearLayout;
import android.widget.SeekBar;
import android.widget.SeekBar.OnSeekBarChangeListener;
import android.widget.Switch;
import android.widget.TextView;

public class Grid_Properties_Dialog extends Dialog {

	LinearLayout llValueInput;

	Switch switchSnap;
	SeekBar SeekBarV;
	SeekBar SeekBarH;
	CheckBox cbGridSym;

	int objID = -1;

	public Grid_Properties_Dialog(Context context) {
		super(context);
		if (context instanceof Activity) {
			setOwnerActivity((Activity) context);
		}

		init();
	}

	public void init() {
		this.requestWindowFeature(Window.FEATURE_NO_TITLE);
		this.setContentView(R.layout.grid_properties_dialog);
		this.getWindow().setBackgroundDrawable(
				new ColorDrawable(android.graphics.Color.TRANSPARENT));

		switchSnap = (Switch) findViewById(R.id.switchSnap);

		SeekBarV = (SeekBar) findViewById(R.id.seekBarVer);
		SeekBarH = (SeekBar) findViewById(R.id.seekBarHor);
		
		cbGridSym=(CheckBox) findViewById(R.id.cbGridSym);

		final TextView tvV = (TextView) findViewById(R.id.textViewVValue);
		final TextView tvH = (TextView) findViewById(R.id.textViewHValue);

		SeekBarV.setOnSeekBarChangeListener(new OnSeekBarChangeListener() {

			@Override
			public void onStopTrackingTouch(SeekBar seekBar) {
				// TODO Auto-generated method stub

			}

			@Override
			public void onStartTrackingTouch(SeekBar seekBar) {
				// TODO Auto-generated method stub

			}

			@Override
			public void onProgressChanged(SeekBar seekBar, int progress,
					boolean fromUser) {
				tvV.setText(progress + "");

			}
		});

		SeekBarH.setOnSeekBarChangeListener(new OnSeekBarChangeListener() {

			@Override
			public void onStopTrackingTouch(SeekBar seekBar) {
				// TODO Auto-generated method stub

			}

			@Override
			public void onStartTrackingTouch(SeekBar seekBar) {
				// TODO Auto-generated method stub

			}

			@Override
			public void onProgressChanged(SeekBar seekBar, int progress,
					boolean fromUser) {
				tvH.setText(progress + "");

			}
		});

		Button btn;

		btn = (Button) this.findViewById(R.id.buttonOK);
		btn.setOnClickListener(new View.OnClickListener() {

			@Override
			public void onClick(View v) {

				OKClicked(null);
			}
		});

		btn = (Button) this.findViewById(R.id.buttonCancel);
		btn.setOnClickListener(new View.OnClickListener() {

			@Override
			public void onClick(View v) {

				CancelClicked(null);
			}
		});
	}

	public void OKClicked(View v) {
		Activity owner = getOwnerActivity();
		if (owner != null) {
			if (owner.getClass().equals(Draw.class)) {
				((Draw) owner).setGridProperties(SeekBarH.getProgress(),
						SeekBarV.getProgress(), switchSnap.isChecked(), cbGridSym.isChecked());
			}
			/*
			 * if(owner.getClass().equals(Home.class))
			 * ((Home)owner).addObject(et_Key.getText().toString()); else
			 * ((ViewCell)owner).addObject(et_Key.getText().toString(),
			 * et_Value.getText().toString());
			 */
			this.hide();
		}

	}

	public void CancelClicked(View v) {
		this.hide();
	}

	public void setValueText(String name) {
		// et_Value.setText(name);

	}

	public void setObjID(int i) {
		objID = i;
	}

}
